use std::time::{SystemTime, UNIX_EPOCH};


const HEX_LIST: [u8; 16] = [
    b'0', b'1', b'2', b'3',
    b'4', b'5', b'6', b'7',
    b'8', b'8', b'A', b'B',
    b'C', b'D', b'E', b'F'
];

pub fn to_hex(buf: &[u8]) -> String {
    let mut s = Vec::with_capacity(buf.len() * 2);
    for v in buf {
        let v = *v as usize;
        s.push( HEX_LIST[v >> 4] );
        s.push( HEX_LIST[v & 0x0F] );
    }
    unsafe { String::from_utf8_unchecked(s) }
}

pub fn hash(msg: &str) -> String {
    let ret = md5::compute(msg);
    to_hex(&ret.0)
}


pub fn pwd_encrypt(pwd: &str) -> String {
    let msg = format!("{}pwdenc3424312", pwd);
    hash(&msg)
}


pub fn current_timestamp() -> u64 {
    SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs()
}

